package ja.lingo.engine.beans.marks;

import ja.lingo.engine.beans.Word;

import java.util.List;

public class MarkHelper {
    public static IMark getMark(Integer type, List<IMark> marks) {
        for (IMark mark : marks) {
            if (mark.getType().equals(type)) {
                return mark;
            }
        }
        return null;
    }

    public static Integer[] getMarkTypes() {
        return new Integer[]{IMark.MARK_A, IMark.MARK_B};
    }

    public static Integer getMarkTypeForValue(Double v) {
        for (Integer markType : getMarkTypes()) {
            Double b = getMarkForBegin(markType);
            Double e = getMarkForEnd(markType);
            if (v >= b && v <= e) {
                return markType;
            }
        }
        return getMarkTypes()[0];
    }

    public static IMark getMark(Integer type, Word word) {
        for (IMark mark : word.getMarks()) {
            if (mark.getType().equals(type)) {
                return mark;
            }
        }
        return null;
    }

    public static void increase(Integer type, Word word) {
        IMark mark = getMark(type, word);
        if (mark != null) {
            mark.increase();
        }
    }

    public static void decrease(Integer type, Word word) {
        IMark mark = getMark(type, word);
        if (mark != null) {
            mark.decrease();
        }
    }

    public static Integer getIncreaseStep(Integer type) {
        switch (type) {
            case 10:
                return 2;
            case 20:
                return 2;
        }
        return null;
    }

    public static Integer getDecreaseStep(Integer type) {
        switch (type) {
            case 10:
                return 2;
            case 20:
                return 2;
        }
        return null;
    }

    public static Double getMarkForBegin(Integer type) {
        switch (type) {
            case 10:
                return 0.;
            case 20:
                return 2.;
        }
        return null;
    }

    public static Double getMarkForEnd(Integer type) {
        switch (type) {
            case 10:
                return 0.;
            case 20:
                return 3.;
        }
        return null;
    }


}
